package com.ttt.adbgui.function;

import com.ttt.adbgui.jcomp.JFrameComponent;
import com.ttt.adbgui.utils.JavaCMD;
import com.ttt.adbgui.utils.RunCMD;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

@Component
@Slf4j
public class AdbMonkey {

    @Autowired
    private JFrameComponent jFrameComponent;
    @Autowired
    private JavaCMD javaCMD;

    // 执行AdbMonkey
    public void startMonkeyClick(JButton jButton, String str){
        MouseListener[] mouseListeners = jButton.getMouseListeners();
        if (mouseListeners.length <= 1){
            jButton.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    int clickCount = e.getClickCount();
                    if (clickCount >=1){
                        JTextArea adbMonkeyTextArea = jFrameComponent.getAdbMonkeyTextArea();
                        String cmd = "shell monkey -help";
                        javaCMD.execAppend(cmd,adbMonkeyTextArea);
                    }
                }
            });
        }
    }
}
